﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenTwitter.SDK;
using OpenTwitter.SDK.Tencent;
using OpenTwitter.SDK.Tencent.API;

namespace TaoTaoKeForQqWeibo
{
    internal class TencentWeibo
    {
        static OAuth oauth = new OAuth("801249975", "f420253bf541ee797dc06c47532fa2eb");

        public static bool WeatherSending { get; set; }

        static internal OAuth Oauth
        {
            get
            {
                return oauth;
            }
        }

        internal static void sendweibo(Action action)
        {
            var dc = new DataHelperDataContext();

            Twitter twitter = new Twitter(Oauth);

            while (WeatherSending)
            {
                var itemsForSend = (from itemsNoSend in dc.taobaoke_items
                                    where itemsNoSend.has_sendtoqq == false
                                    select itemsNoSend
                     ).Take<taobaoke_item>(40);

                foreach (var p in itemsForSend)
                {
                    twitter.Add(p.title + p.click_url, p.pic_url, "127.0.0.1");
                    p.has_sendtoqq = true;
                    Console.WriteLine(p.title);
                    Thread.Sleep(1000);
                }
                 
                dc.SubmitChanges();

                Thread.Sleep(5000);
            }

            action();
        }
    }
}
